// @@@ START COPYRIGHT @@@
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.
//
// @@@ END COPYRIGHT @@@

package org.trafodion.jdbc.t4;

import java.nio.charset.CharacterCodingException;
import java.nio.charset.UnsupportedCharsetException;
import java.sql.SQLException;

class odbc_Dcs_StopSrvr_exc_ {

	int exception_nr;
	int exception_detail;
	//
	// If the third element is not zero, then it is an offset
	// to a character array that contains a message.
	//
	String ErrorText;
	int errorCode;

	//
	// It looks like ODBC doesn't generate error text in all
	// error cases, so the following variable will contain
	// any error text generated by this JDBC driver.
	// Note, this variable is not part of the message, but it
	// represents a value stored in the TrafT4Messages_*.properties file.
	//

	String clientErrorText;

	static final int odbcas_ASSvc_StopSrvr_ASParamError_exn_ = 1;
	static final int odbcas_ASSvc_StopSrvr_ASNotAvailable_exn_ = 2;
	static final int odbcas_ASSvc_StopSrvr_SrvrNotFound_exn_ = 3;
	static final int odbcas_ASSvc_StopSrvr_SrvrInUseByAnotherClient_exn_ = 4;
	static final int odbcas_ASSvc_StopSrvr_ProcessStopError_exn_ = 5;

	// -------------------------------------------------------------------
	odbc_Dcs_StopSrvr_exc_() {
		// Do nothing constructor
	}

	// -------------------------------------------------------------------
	void extractFromByteArray(LogicalByteArray buffer1, InterfaceConnection ic) throws SQLException,
			UnsupportedCharsetException, CharacterCodingException {
		exception_nr = buffer1.extractInt();
		exception_detail = buffer1.extractInt();

		String temp0 = Integer.toString(exception_nr);
		String temp1 = Integer.toString(exception_detail);

		switch (exception_nr) {
		case TRANSPORT.CEE_SUCCESS:
			break;
		case odbcas_ASSvc_StopSrvr_ASParamError_exn_:
		case odbcas_ASSvc_StopSrvr_SrvrNotFound_exn_:
		case odbcas_ASSvc_StopSrvr_ProcessStopError_exn_:
		case odbcas_ASSvc_StopSrvr_SrvrInUseByAnotherClient_exn_:
			ErrorText = ic.decodeBytes(buffer1.extractString(), 1);
			throw TrafT4Messages.createSQLException(null, ic.getLocale(), "ids_program_error", ErrorText);
		case odbcas_ASSvc_StopSrvr_ASNotAvailable_exn_:
			ErrorText = ic.decodeBytes(buffer1.extractString(), 1);
			throw TrafT4Messages.createSQLException(null, ic.getLocale(), "ids_dcs_srvr_not_available", ErrorText);

		default:
			throw TrafT4Messages.createSQLException(null, ic.getLocale(), "unknown_error", null);
		} // end switch
	} // end extractFromByteArray
} // end odbc_Dcs_StopSrvr_exc_
